﻿using FB.Helpers;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace FB.Extensions
{
    public static class EnumExtension
    {
        public static MvcHtmlString DisplayForEnum(this HtmlHelper helper, Enum en)
        {
            return new MvcHtmlString(EnumHelper.GetDescription(en));
        }


        public static MvcHtmlString LabelForEnum(this HtmlHelper helper, Enum en, object htmlAttributes = null)
        {
            var attributes = (IDictionary<string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
            var tagBuilder = new TagBuilder("label");
            tagBuilder.MergeAttributes(attributes, true);
            tagBuilder.InnerHtml = EnumHelper.GetDescription(en);

            return new MvcHtmlString(tagBuilder.ToString(TagRenderMode.Normal));
        }


        public static MvcHtmlString DropDownListForEnum<T>(this HtmlHelper helper, string name)
        {
            return DropDownListForEnum<T>(helper, name, null, null);
        }
        public static MvcHtmlString DropDownListForEnum<T>(this HtmlHelper helper, string name, string optionLabel)
        {
            return DropDownListForEnum<T>(helper, name, optionLabel, null);
        }

        public static MvcHtmlString DropDownListForEnum<T>(this HtmlHelper helper, string name, string optionLabel, Object htmlAttributes)
        {
            return DropDownListForEnum(helper, typeof(T), name, optionLabel, htmlAttributes);
        }

        static MvcHtmlString DropDownListForEnum(HtmlHelper helper, Type EnumType, string name, string optionLabel, Object htmlAttributes)
        {
            var items = EnumHelper.EnumToSelectListItem(EnumType);
            return helper.DropDownList(name, items, optionLabel, htmlAttributes);
        }


        //public static MvcHtmlString EnumDropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, Type EnumType, Object htmlAttributes)
        //{
        //    return EnumDropDownListFor(htmlHelper, expression, EnumType, htmlAttributes);
        //}

        //static MvcHtmlString EnumDropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, Type EnumType, string name, Object htmlAttributes)
        //{
        //    var items = EnumHelper.EnumToSelectListItem(EnumType);
        //    return htmlHelper.DropDownListFor(expression, items, htmlAttributes);
        //}



    }
}
